import os
from IPy import IP
from multiprocessing import Pool, current_process

ip = IP('192.168.0.0/24')
def ping_ip(i):
    ret = os.system("ping -c 1 -i 0.01 -w 1 %s &>/dev/null"%i)
    if ret == 0:
        print("%s is online"%i)
    else:
        print("%s is offline"%i)
if __name__ == "__main__":
    p = Pool(processes=4)
    #pool_lst = []
    for i in ip:
        p.apply_async(func = ping_ip,args=(i,))
                #池子不再接收任务
    p.close()
        #等待子进程执行完毕后 再关闭进程池
    p.join()

